home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 August: Tool Chest / Dev.CD Aug 98 TC.toast / Sample Code / Snippets / Sound / SndPlayDoubleBuffer / _headers / DoubleBufferFromFile.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-11-15  |  13.1 KB  |  367 lines  |  [TEXT/CWIE]

  1. /*
  2. **    Apple Macintosh Developer Technical Support
  3. **
  4. **    Headers for routines demonstrating how to play sound from disk using SndPlayDoubleBuffer.
  5. **
  6. **    by Mark Cookson, Apple Developer Technical Support
  7. **
  8. **    File:    DoubleBufferFromFile.h
  9. **
  10. **    Copyright ©1996 Apple Computer, Inc.
  11. **    All rights reserved.
  12. **
  13. **    You may incorporate this sample code into your applications without
  14. **    restriction, though the sample code has been provided "AS IS" and the
  15. **    responsibility for its operation is 100% yours.  However, what you are
  16. **    not permitted to do is to redistribute the source as "Apple Sample
  17. **    Code" after having made changes. If you're going to re-distribute the
  18. **    source, we require that you make it clear in the source that the code
  19. **    was descended from Apple Sample Code, but that you've made changes.
  20. */
  21.  
  22. #ifndef __DOUBLEBUFFERFROMFILE__
  23. #define __DOUBLEBUFFERFROMFILE__
  24.  
  25. #include <AIFF.h>
  26. #include <Sound.h>
  27. #include <Files.h>
  28. #include <MixedMode.h>
  29. #include <StandardFile.h>
  30. #include <Fonts.h>
  31. #include <SegLoad.h>
  32. #include <Resources.h>
  33. #include <FixMath.h>
  34.  
  35. #if GENERATINGPOWERPC
  36. #include <fp.h>
  37. #endif
  38.  
  39. #ifndef __SOUNDSTRUCT__
  40. #include "SoundStruct.h"
  41. #endif
  42.  
  43. #ifndef __MYGESTALT__
  44. #include "MyGestalt.h"
  45. #endif
  46.  
  47. #ifndef __PRIVATE_DBFFFUNC__
  48. #include "Private_DBFFFunctions.h"
  49. #endif
  50.  
  51. #ifndef __INTERRUPT_ROUTINES__
  52. #include "Interrupt_Routines.h"
  53. #endif
  54.  
  55. #ifndef __DBFFERRORS__
  56. #include "DBFF_Errors.h"
  57. #endif
  58.  
  59. #ifndef __DEFINES__
  60. #include "Defines.h"
  61. #endif
  62.  
  63. /* Function definitions */
  64.  
  65. /*    Purpose:        This creates a new SoundInfo structure and initializes
  66.                     it by calling ASoundInit.
  67.     Side Effects:    None.
  68. */
  69. /*-----------------------------------------------------------------------*/
  70. SoundInfoPtr    ASoundNew                (OSErr *theErr);
  71. /*-----------------------------------------------------------------------*/
  72.  
  73. /*
  74.     Purpose:        Display a StandardFile dialog to select an AIFF file.
  75.                     Open the file selected by the user.
  76.     Side Effects:    None.
  77. */
  78. /*-----------------------------------------------------------------------*/
  79. OSErr            ASoundGetFileToPlay        (SoundInfoPtr theSoundInfo);
  80. /*-----------------------------------------------------------------------*/
  81.  
  82. /*
  83.     Purpose:        Checks a file to see if its header can be parsed
  84.                     and the file can be played.
  85.                     
  86.                     This will return an error if the sound will not play,
  87.                     returning noErr means that sound will play.
  88.     Side Effects:    None.
  89. */
  90. /*-----------------------------------------------------------------------*/
  91. OSErr            ASoundCanThisPlay        (CInfoPBPtr theFileInfo);
  92. /*-----------------------------------------------------------------------*/
  93.  
  94. /*
  95.     Purpose:        Wrapper function called to get ready to play a sound.
  96.                     Use this if you want to make sure that there is enough
  97.                     memory to play the sound.
  98.     Side Effects:    This will call routines that will allocate memory needed
  99.                     to all of the various structures needed by the Sound Manager
  100.                     and memory to be used as the sounds' buffers.
  101. */
  102. /*-----------------------------------------------------------------------*/
  103. OSErr            ASoundReadyForPlaying    (SoundInfoPtr theSoundInfo,
  104.                                         unsigned long bufferSize);
  105. /*-----------------------------------------------------------------------*/
  106.  
  107. /*
  108.     Purpose:        Call this after you have called ASoundReadyForPlaying to
  109.                     start playing the sound you prepaired.
  110.     Side Effects:    Starts the sound playing.
  111. */
  112. /*-----------------------------------------------------------------------*/
  113. OSErr            ASoundPlay                (SoundInfoPtr theSoundInfo);
  114. /*-----------------------------------------------------------------------*/
  115.  
  116. /*
  117.     Purpose:        Wrapper function called to start playing a sound.
  118.                     Use this if you are pretty sure the sound will play, or
  119.                     just don't care specifically what goes wrong.
  120.     Side Effects:    This will call routines that will allocate memory needed
  121.                     to all of the various structures needed by the Sound Manager
  122.                     and memory to be used as the sounds' buffers.
  123. */
  124. /*-----------------------------------------------------------------------*/
  125. OSErr            ASoundStartPlaying        (SoundInfoPtr theSoundInfo,
  126.                                         unsigned long bufferSize);
  127. /*-----------------------------------------------------------------------*/
  128.  
  129. /*
  130.     Purpose:        Stops the currently playing sound.
  131.     Side Effects:    Stopping the currently playing sound will cause the
  132.                     sound completion routine to run.
  133. */
  134. /*-----------------------------------------------------------------------*/
  135. OSErr            ASoundStop                (SoundInfoPtr theSoundInfo);
  136. /*-----------------------------------------------------------------------*/
  137.  
  138. /*
  139.     Purpose:        Wrapper so the user doesn't have to keep track of if
  140.                     the sound is playing or not.
  141.     Side Effects:    If resuming a sound and the user had also called
  142.                     ASoundPauseForAdjust this will reinstall the sound
  143.                     completion callback.
  144. */
  145. /*-----------------------------------------------------------------------*/
  146. OSErr            ASoundPause                (SoundInfoPtr theSoundInfo);
  147. /*-----------------------------------------------------------------------*/
  148.  
  149. /*
  150.     Purpose:        If the sound is paused, resume playing.  If the sound is
  151.                     playing, pause playing.
  152.                     This differs from ASoundPause because it actually stops
  153.                     the sound instead of pausing it.  When the sound is
  154.                     paused for adjusting you can reset where the sound will
  155.                     next start playing from without having to play the
  156.                     remainder of the current buffer.  This routine is used
  157.                     for the QuickTime style playing.
  158.     Side Effects:    Removes the callback from the sound channel because
  159.                     otherwise while adjusting the sound the Sound Manager
  160.                     would call our clean up routine.
  161.                     When resuming a sound ASoundStartPlaying will install
  162.                     our callback routine if necessary (if the sound wasn't
  163.                     already paused).
  164. */
  165. /*-----------------------------------------------------------------------*/
  166. OSErr            ASoundPauseForAdjust    (SoundInfoPtr theSoundInfo);
  167. /*-----------------------------------------------------------------------*/
  168.  
  169. /*
  170.     Purpose:        Sound is done playing, dispose of the memory we no
  171.                     longer need.
  172.     Side Effects:    None.
  173. */
  174. /*-----------------------------------------------------------------------*/
  175. OSErr            ASoundDonePlaying        (SoundInfoPtr theSoundInfo,
  176.                                         unsigned long options);
  177. /*-----------------------------------------------------------------------*/
  178.  
  179. /*
  180.     Purpose:        Returns the channel for the sound in case you want to
  181.                     send it specific commands.
  182.     Side Effects:    None.
  183. */
  184. /*-----------------------------------------------------------------------*/
  185. SndChannelPtr    ASoundGetChan            (SoundInfoPtr theSoundInfo);
  186. /*-----------------------------------------------------------------------*/
  187.  
  188. /*
  189.     Purpose:        Returns the name of the file containing the currently
  190.                     playing sound.
  191.     Side Effects:    None.
  192. */
  193. /*-----------------------------------------------------------------------*/
  194. OSErr            ASoundGetSoundName        (SoundInfoPtr theSoundInfo,
  195.                                         Str255 theName);
  196. /*-----------------------------------------------------------------------*/
  197.  
  198. /*
  199.     Purpose:        Gets the number of the current buffer
  200.                     (in the range 1 to ASoundGetNumBuffers()) of the
  201.                     currently playing sound.
  202.     Side Effects:    None.
  203. */
  204. /*-----------------------------------------------------------------------*/
  205. long            ASoundGetCurBuffer        (SoundInfoPtr theSoundInfo);
  206. /*-----------------------------------------------------------------------*/
  207.  
  208. /*
  209.     Purpose:        Sets which buffer should be the next buffer to play
  210.                     from (in the range 1 to ASoundGetNumBuffers())
  211.                     for the currently playing sound.
  212.     Side Effects:    None.
  213. */
  214. /*-----------------------------------------------------------------------*/
  215. OSErr            ASoundSetCurBuffer        (SoundInfoPtr theSoundInfo,
  216.                                         long newValue);
  217. /*-----------------------------------------------------------------------*/
  218.  
  219. /*
  220.     Purpose:        Gets the number of buffers that the currently playing
  221.                     sound will need to play in its entirety.
  222.     Side Effects:    None.
  223. */
  224. /*-----------------------------------------------------------------------*/
  225. long            ASoundGetNumBuffers        (SoundInfoPtr theSoundInfo);
  226. /*-----------------------------------------------------------------------*/
  227.  
  228. /*
  229.     Purpose:        Gets the length (in bytes) of the currently playing
  230.                     sound.  This number does not include any header bytes.
  231.     Side Effects:    None.
  232. */
  233. /*-----------------------------------------------------------------------*/
  234. long            ASoundGetNumTotalBytes    (SoundInfoPtr theSoundInfo);
  235. /*-----------------------------------------------------------------------*/
  236.  
  237. /*
  238.     Purpose:        Gets the number of bytes that will be played by the end
  239.                     of the current buffer of the currently playing sound.
  240.     Side Effects:    None.
  241. */
  242. /*-----------------------------------------------------------------------*/
  243. long            ASoundGetBytesCopied    (SoundInfoPtr theSoundInfo);
  244.  
  245. /*
  246.     Purpose:        Sets the location in the file where the next buffer
  247.                     should be filled from for the currently playing sound.
  248.     Side Effects:    None.
  249. */
  250. /*-----------------------------------------------------------------------*/
  251. OSErr            ASoundSetBytesCopied    (SoundInfoPtr theSoundInfo,
  252.                                         long newValue);
  253. /*-----------------------------------------------------------------------*/
  254.  
  255. /*
  256.     Purpose:        Gets the size of a buffer of the currently playing
  257.                     sound.  Multiply by two to know how much memory is
  258.                     reserved for buffering the currently playing sound.
  259.     Side Effects:    None.
  260. */
  261. /*-----------------------------------------------------------------------*/
  262. long            ASoundGetBufferSize        (SoundInfoPtr theSoundInfo);
  263. /*-----------------------------------------------------------------------*/
  264.  
  265. /*
  266.     Purpose:        Gets the UPP for the function that should be called when
  267.                     the currently playing sound finishes.
  268.     Side Effects:    None.
  269. */
  270. /*-----------------------------------------------------------------------*/
  271. SndCallBackUPP    ASoundGetSoundCallBack    (SoundInfoPtr theSoundInfo);
  272. /*-----------------------------------------------------------------------*/
  273.  
  274. /*
  275.     Purpose:        Sets the function that should be called when the the
  276.                     currently playing sound finishes.
  277.     Side Effects:    None.
  278. */
  279. /*-----------------------------------------------------------------------*/
  280. OSErr            ASoundSetSoundCallBack    (SoundInfoPtr theSoundInfo,
  281.                                         void* newValue);
  282. /*-----------------------------------------------------------------------*/
  283.  
  284. OSErr            ASoundMute                (SoundInfoPtr theSoundInfo,
  285.                                         Boolean newValue);
  286.  
  287. Boolean            ASoundIsMute            (SoundInfoPtr theSoundInfo);
  288.  
  289. /*
  290.     Purpose:        Says to play the currently playing sound backwards
  291.                     (reverses the sound in the buffer).
  292.     Side Effects:    Takes effect when the next sound buffer gets filled.
  293. */
  294. /*-----------------------------------------------------------------------*/
  295. OSErr            ASoundPlayBackwards        (SoundInfoPtr theSoundInfo,
  296.                                         Boolean newValue);
  297. /*-----------------------------------------------------------------------*/
  298.  
  299. /*
  300.     Purpose:        Returns true if the currently playing sound's buffer
  301.                     is set to be reversed.
  302.     Side Effects:    None.
  303. */
  304. /*-----------------------------------------------------------------------*/
  305. Boolean            ASoundIsBackwards        (SoundInfoPtr theSoundInfo);
  306. /*-----------------------------------------------------------------------*/
  307.  
  308. /*
  309.     Purpose:        Returns true if the sound has finished playing.
  310.     Side Effects:    None.
  311. */
  312. /*-----------------------------------------------------------------------*/
  313. Boolean            ASoundIsDone            (SoundInfoPtr theSoundInfo);
  314. /*-----------------------------------------------------------------------*/
  315.  
  316. /*
  317.     Purpose:        Changes the volume of the currently playing sound.
  318.                     The values you pass in are added to the current values.
  319.                     Negitive values will decrease the volume, positive values
  320.                     will increase the volume.
  321.     Side Effects:    None.
  322. */
  323. /*-----------------------------------------------------------------------*/
  324. OSErr            ASoundChangeVolume        (SoundInfoPtr theSoundInfo,
  325.                                         unsigned short leftVol,
  326.                                         unsigned short rightVol);
  327. /*-----------------------------------------------------------------------*/
  328.  
  329. /*
  330.     Purpose:        Gets the volume of the currently playing sound.
  331.     Side Effects:    None.
  332. */
  333. /*-----------------------------------------------------------------------*/
  334. OSErr            ASoundGetVolume            (SoundInfoPtr theSoundInfo,
  335.                                         unsigned short *leftVol,
  336.                                         unsigned short *rightVol);
  337. /*-----------------------------------------------------------------------*/
  338.  
  339. /*
  340.     Purpose:        Sets the volume of the currently playing sound.
  341.     Side Effects:    None.
  342. */
  343. /*-----------------------------------------------------------------------*/
  344. OSErr            ASoundSetVolume            (SoundInfoPtr theSoundInfo,
  345.                                         unsigned short leftVol,
  346.                                         unsigned short rightVol);
  347. /*-----------------------------------------------------------------------*/
  348.  
  349. /*
  350.     Purpose:        Gets the rate multiplier of the currently playing sound.
  351.     Side Effects:    None.
  352. */
  353. /*-----------------------------------------------------------------------*/
  354. OSErr            ASoundGetRateMul        (SoundInfoPtr theSoundInfo,
  355.                                         UnsignedFixed *theRateMul);
  356. /*-----------------------------------------------------------------------*/
  357.  
  358. /*
  359.     Purpose:        Gets the rate multiplier of the currently playing sound.
  360.     Side Effects:    None.
  361. */
  362. /*-----------------------------------------------------------------------*/
  363. OSErr            ASoundSetRateMul        (SoundInfoPtr theSoundInfo,
  364.                                         UnsignedFixed theRateMul);
  365. /*-----------------------------------------------------------------------*/
  366.  
  367. #endif